<template>
  <el-table :data="tableData" style="width: 100%" border ref="tableDom">
    <el-table-column prop="date" label="日期" width="180"></el-table-column>
    <el-table-column prop="name" label="姓名" width="180"></el-table-column>
    <el-table-column prop="address" label="地址"></el-table-column>
  </el-table>

  <div style="margin-top:30px;">
    <el-table :data="list" border style="width:100%;margin-top:20px" v-loading="tableLoading">
        <el-table-column v-for="items in ChartsTabData" :key="items.index" :label="items">
        <template slot-scope="scope">	
          <span>{{ getDataName(scope.row,items) }}</span> 
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import dataMixins from './dataJosn.js'
export default {
  mixins: [dataMixins],
  data () {
    return {
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ],
      list: []
    }
  },
  created () {
    console.log('tableList', this.tableList)
    this.initData(this.tableList.data)
  },
  methods: {
    getDataName (scope, items) {
      return scope[items]
    },
    initData (data) {
      console.log('data', data)
      var arr = []
      for (var item of data.list) {
        var obj = {}
        for (var colName in item) {
          // debugger
          console.log('colName', colName)
          for (var title of data.title) {
            // debugger
            if (title.ColName === colName) {
              // debugger
              var key = colName + '-' + title.DisplayLabel
              var value = item[colName]
              obj[key] = value
              break
            }
          }
        }
        arr.push(obj)
      }
      console.log('arr', arr)
      this.list = arr
    }
  }
}
</script>
